package com.youlu.campus.admin.community.controller;

import com.youlu.campus.admin.annotation.RequestActivityAuth;
import com.youlu.campus.entity.VO.req.ActivityChannelPvUvQueryReq;
import com.youlu.campus.entity.VO.req.ActivityChannelStatisticsCommandReq;
import com.youlu.campus.entity.VO.req.ActivityChannelStatisticsQueryReq;
import com.youlu.campus.service.activity.ActivityChannelStatisticsService;
import com.youlu.campus.service.platform.PlatformConfigService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityChannelStatisticsController {

    @Autowired
    private ActivityChannelStatisticsService activityChannelStatisticsService;

    @Autowired
    private PlatformConfigService platformConfigService;


    @PostMapping("/activity/channel-statistics/list")
    public QResult list(@RequestBody ActivityChannelStatisticsQueryReq activityChannelStatisticsQueryReq) {
        return QResult.success(activityChannelStatisticsService.list(activityChannelStatisticsQueryReq));
    }

    @PostMapping("/activity/channel-statistics/save")
    @RequestActivityAuth(activityId = "#commandReq.activityId")
    public QResult list(@RequestBody ActivityChannelStatisticsCommandReq commandReq) {
        activityChannelStatisticsService.saveOrUpdate(commandReq);
        return QResult.success(null);
    }


    /**
     * 生成短链接
     * @param id
     * @return
     */
    @GetMapping("/activity/channel-statistics/short-url/generate")
    public QResult generateShortUrl(@RequestParam("id") String id) {
        return QResult.success(platformConfigService.getShortUrlDomain() + "/" + activityChannelStatisticsService.generateShortUrl(id));
    }

    @PostMapping("/activity/channel-statistics/count")
    public QResult list(@RequestBody ActivityChannelPvUvQueryReq req) {
        return QResult.success(activityChannelStatisticsService.listPvUv(req));
    }




}
